import { getClassifyList } from "../../utils/api";
import { getSearchList } from "../../utils/api.js";

export default {
  namespaced: true,
  state() {
    return {
      classifyList: null,
      quickSearchValue: '',
      providerList: [],
    }
  },
  mutations: {
    getClassify(state, { result }) {
      state.classifyList = result;
      console.log(state.classifyList);
    },
    //去搜索页搜索
    goSearch(state, payload) {
      state.quickSearchValue = payload;
      console.log(state.quickSearchValue);
    },

    //搜索请求
    onSearch(state, { result }) {
      state.providerList = result;
      console.log(state.providerList);
    }
  },
  actions: {
    async getClassify({ commit }) {
      const res = await getClassifyList();
      commit("getClassify", res);
      console.log(res);
    },

    //去搜索页搜索
    async goSearch({ dispatch, commit }, val) {
      console.log(val);
      dispatch("onSearch", val);
      commit("goSearch", val);
    },

    //搜索请求
    async onSearch({ commit }, val) {
      const res = await getSearchList({ keyword: val,token:localStorage.getItem('userToken')});
      commit("onSearch", res);
    },
  },
}